package other;


import java.util.HashSet;

/**
 * 全排列的实现
 */
public class AllSort {


  private static HashSet<String> set = new HashSet();

  public static void sort(char[] chars, int i) {
    if (chars == null || chars.length < 0) {
      return;
    }

    if (i == chars.length - 1) {
//            System.out.println(String.valueOf(chars));
      set.add(String.valueOf(chars));
    } else {
      for (int j = i; j < chars.length; j++) {
        swap(chars, i, j);
        sort(chars, i + 1);
        swap(chars, i, j);
      }
    }
  }


  public static void swap(char[] chars, int i, int j) {
    char temp = chars[i];
    chars[i] = chars[j];
    chars[j] = temp;
  }


  public static void getResult(String str) {
    if (str == null || str.length() < 0) {
      return;
    }
    char[] chars = str.toCharArray();
    sort(chars, 0);
    for (String s : set) {
      if (s.charAt(2) == '4') {
        continue;
      }
      if (s.contains("35") || s.contains("53")) {
        continue;
      }
      System.out.println(s);
    }
  }


  public static void main(String args[]) {
    String str = "122345";
    getResult(str);
  }
}
